package com.ruoyi.system.service;

import com.ruoyi.system.api.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

@Service
public class UserService {
    @Resource
    ISysUserService iSysUserService;


    @Autowired
    private ThreadPoolTaskExecutor threadPoolTaskExecutor;

    public void addUsers(int count) {
        RandomNameGenerator generator = new RandomNameGenerator();
        generator.generateNames(count);
        Set<String> names = generator.getGeneratedNames();
        for (String name : names) {
            threadPoolTaskExecutor.execute(() -> {
                System.err.println(name);
                SysUser user = new SysUser();
                user.setUserName(name);
                user.setPassword("$10$uVOv5iXqq2NRyu0epTmn5OA6zbKMNbgUfu6dnNHPTy0NB9CNeRM2u");
                user.setEmail("123@qq.com");
                user.setRemark("普通用户");
                user.setAddress("山西");
                user.setNickName("程序猿的浪漫");
                user.setAge(12);
                iSysUserService.insertUser(user);
            });
        }
    }
}